/* $Header: sig_time.c,v 2.2 01/10/02 10:33:05 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1992                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME:  sig_time.c                                            */
/* ============                                                        */
/*                                                                     */
/* Author:  Lesley Freed                                               */
/*                                                                     */
/* MODULE PURPOSE:  To provide the Set, Get, and Check functions for   */
/*                  the time table to the signal path parameters.      */
/*                                                                     */
/***********************************************************************/


/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <p_wkfile.h>
#include <wkfile.h>
#include <ramps.h>
#include <zone_config.h>
#include <i_op.h>
#include <zone_status.h>
#include <status.h>
#include <error.h>
#include <sig_types.h>
#include <sig_ui.h>
#include <sigpath.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/


/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/


/*****************************/
/*   LOCAL DEFINES           */
/*****************************/


/*****************************/
/*   STATIC VARIABLES        */
/*****************************/


/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/

void ResetSigPathState( void )
{
   UpdateSignalStatus(&Signal1);	
   UpdateSignalStatus(&Signal2);	
}

void RTTSetSignal1Type( INT32 type )
{
   (void)SetSignalTypeMain( pSIGNAL1, (SIG_TYPE)type, FALSE );
}

void RTTSetSignal2Type( INT32 type )
{
   (void)SetSignalTypeMain( pSIGNAL2, (SIG_TYPE)type, FALSE );
}

void RTTSetSignal1Zero( INT32 zero )
{
   INTERRUPTS_OFF

    if ( zero == (INT32)RTT_ZERO_ON_VALUE )
    {
        Signal1.zero = GetSignalValue( &Signal1 );
        Signal1.zero_attn_on_off |= ZERO_ON_MASK;
    }
    else if ( zero == (INT32)RTT_ZERO_OFF_VALUE )
    {
        Signal1.zero_attn_on_off &= ZERO_OFF_MASK;
    }
    else
    {
        Signal1.zero = zero;
        Signal1.zero_attn_on_off |= ZERO_ON_MASK;
    }

   INTERRUPTS_ON
}

void RTTSetSignal2Zero( INT32 zero )
{
   INTERRUPTS_OFF

    if ( zero == (INT32)RTT_ZERO_ON_VALUE )
    {
       Signal2.zero = GetSignalValue( &Signal2 );
       Signal2.zero_attn_on_off |= ZERO_ON_MASK;

    }
    else if ( zero == (INT32)RTT_ZERO_OFF_VALUE )
    {
        Signal2.zero_attn_on_off &= ZERO_OFF_MASK;
    }
    else
    {
        Signal2.zero = zero;
        Signal2.zero_attn_on_off |= ZERO_ON_MASK;
    }

   INTERRUPTS_ON
}

void RTTSetSignal1Range( INT32 range )
{
   INTERRUPTS_OFF                       /* protect change */

      Signal1.range = (U_INT8)range;

   INTERRUPTS_ON                        /* release protection */
}

void RTTSetSignal2Range( INT32 range )
{
   INTERRUPTS_OFF                       /* protect change */

      Signal2.range = (U_INT8)range;

   INTERRUPTS_ON                        /* release protection */
}

void RTTSetSignal1Attn( INT32 attn )
{
   INTERRUPTS_OFF                       /* protect change */

      Signal1.attn = (U_INT8)attn;

   INTERRUPTS_ON                        /* release protection */
}

void RTTSetSignal2Attn( INT32 attn )
{
   INTERRUPTS_OFF                       /* protect change */

      Signal2.attn = (U_INT8)attn;

   INTERRUPTS_ON                        /* release protection */
}

/* Seaquest additions */

void RTTStoreSignal1Value( INT32 unused )
{
   (void)unused;

   INTERRUPTS_OFF
    Signal1.stored_value = GetSignalValue( &Signal1 );
   INTERRUPTS_ON
}

void RTTStoreSignal2Value( INT32 unused )
{
   (void)unused;

   INTERRUPTS_OFF
    Signal2.stored_value = GetSignalValue( &Signal2 );
   INTERRUPTS_ON
}

void RTTSignal1ZeroLessVal( INT32 unused )
{
   (void)unused;
   INTERRUPTS_OFF

/* REVISIT: add clamping */
    Signal1.zero = GetSignalValue( &Signal1 ) - Signal1.stored_value;
    Signal1.zero_attn_on_off |= ZERO_ON_MASK;

   INTERRUPTS_ON
}

void RTTSignal2ZeroLessVal( INT32 unused )
{
   (void)unused;
   INTERRUPTS_OFF

/* REVISIT: add clamping */
    Signal2.zero = GetSignalValue( &Signal2 ) - Signal2.stored_value;
    Signal2.zero_attn_on_off |= ZERO_ON_MASK;

   INTERRUPTS_ON
}

void RTTFreezeSignal1( INT32 unused )
{
   (void)unused;

   INTERRUPTS_OFF
    Signal1.zero_attn_on_off |= FREEZE_SIG_ON_MASK;
   INTERRUPTS_ON
}

void RTTFreezeSignal2( INT32 unused )
{
   (void)unused;

   INTERRUPTS_OFF
    Signal2.zero_attn_on_off |= FREEZE_SIG_ON_MASK;
   INTERRUPTS_ON
}

void RTTResumeSignal1( INT32 unused )
{
   (void)unused;

   INTERRUPTS_OFF
    if (Signal1.zero_attn_on_off & FREEZE_SIG_ON_MASK)
    {
       Signal1.zero_attn_on_off |= RESUME_SIG_ON_MASK;
    }
   INTERRUPTS_ON
}

void RTTResumeSignal2( INT32 unused )
{
   (void)unused;
 
   INTERRUPTS_OFF
    if (Signal2.zero_attn_on_off & FREEZE_SIG_ON_MASK)
    {
       Signal2.zero_attn_on_off |= RESUME_SIG_ON_MASK;
    }
   INTERRUPTS_ON
}
